import org.apache.commons.math3.util.Combinations;
import org.apache.commons.math3.util.CombinatoricsUtils;

import java.util.Arrays;
import java.util.Iterator;

/**
 * @Description TODO
 * @Date 2022/3/29 15:45
 * @Author 轻歌
 */
public class CombinationList {
    public static void main(String[] args) {
        System.out.println("共"+CombinatoricsUtils.binomialCoefficient(11, 6)+"种组合：");
        System.out.println(Arrays.deepToString(allCombList(5, 2)));
    }
    public static  int[][] allCombList(int n, int k){
        //todo 从 n 个数中取 k 个，找出所有的组合数
        long count = CombinatoricsUtils.binomialCoefficient(n, k);

        int[][] indexs = new int[Math.toIntExact(count)][k];
        Combinations combinations = new Combinations(n, k);
        Iterator<int[]> iterator = combinations.iterator();
        int temp = 0;
        while (iterator.hasNext()){
            int[] next = iterator.next();
            indexs[temp] = Arrays.copyOf(next, k);
            temp++;
        }
        return indexs;
    }
}
